<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>百朋后台管理系统</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/demo.css">
    <script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<div class="report_table">
    <table id="dg" class="easyui-datagrid" title="Row Editing in DataGrid" style="width:100%;height:405px"
            data-options="
                rownumbers:true,
                iconCls: 'icon-edit',
                singleSelect: true,
                toolbar: '#tb',
                url: '../../report/loaninforeport/loaninfo_report_underline',
                method: 'get',
                onDblClickRow: onClickRow,
                pagination:true,
                pageSize:10
            ">
        <thead data-options="frozen:true">
        <tr>
            <th field="loaninforeport_contractnum" width="10%" align="center">分期编号</th>
            <!-- <th field="loaninforeport_contractnum" width="10%" align="center" data-options="editor:{type:'numberbox',options:{required:true,missingMessage:'此项不能为空'}}">分期编号</th> -->
            <th field="loaninforeport_name" width="10%" align="center" data-options="editor:{type:'textbox',options:{required:true,missingMessage:'此项不能为空'}}">姓名</th>
            <th field="loaninforeport_cardnum" width="15%" align="center" data-options="editor:{type:'textbox',options:{required:true,missingMessage:'此项不能为空',validType:'length[18,18]',invalidMessage:'请填写正确的身份证号码'}}">身份证号码</th>
        </tr>
        </thead>
        <thead>
        <tr>
            <th field="loaninforeport_opendate" width="10%" align="center" data-options="editor:{type:'datebox',options:{formatter:myformatter2,parser:myparser2,required:true,editable:false,missingMessage:'此项不能为空'}}">开户日期</th>
            <th field="loaninforeport_enddate" width="10%" align="center" data-options="editor:{type:'datebox',options:{formatter:myformatter2,parser:myparser2,required:true,editable:false,missingMessage:'此项不能为空'}}">到期日期</th>
            <th field="loaninforeport_grantdegree" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">授信额度</th>
            <th field="loaninforeport_sgrantdegree" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">共享授信额度</th>
            <th field="loaninforeport_maxdebt" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">最大负债额</th>
            <th field="loaninforeport_repaymonth" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'length[1,2]',invalidMessage:'请填写正确的月数'}}">还款月数</th>
            <th field="loaninforeport_remainmonth" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'length[1,2]',invalidMessage:'请填写正确的月数'}}">剩余还款月数</th>
            <th field="loaninforeport_treattime" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'length[1,2]',invalidMessage:'请填写正确的期数'}}">协定还款期数</th>
            <th field="loaninforeport_treatmoney" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">协定还款额</th>
            <th field="loaninforeport_repaydown" width="10%" align="center" data-options="editor:{type:'datebox',options:{formatter:myformatter2,parser:myparser2,required:true,editable:false,missingMessage:'此项不能为空'}}">借款还清日期</th>
            <th field="loaninforeport_recentrepay" width="10%" align="center" data-options="editor:{type:'datebox',options:{formatter:myformatter2,parser:myparser2,required:true,editable:false,missingMessage:'此项不能为空'}}">最近还清日期</th>
            <th field="loaninforeport_mothpayshould" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">本月应还款金额</th>
            <th field="loaninforeport_mothpayreal" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">本月实际还款金额</th>
            <th field="loaninforeport_balance" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">余额</th>
            <th field="loaninforeport_overdue" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'length[1,2]',invalidMessage:'请填写正确的期数'}}">当前逾期期数</th>
            <th field="loaninforeport_overduemoney" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">当前逾期金额</th>
            <th field="loaninforeport_overduea" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">逾期31~60天未归还本金</th>
            <th field="loaninforeport_overdueb" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">逾期61~90天未归还本金</th>
            <th field="loaninforeport_overduec" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">逾期91~180天未归还本金</th>
            <th field="loaninforeport_overdued" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">逾期180天以上未归还本金</th>
            <th field="loaninforeport_overduesum" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'length[1,3]',invalidMessage:'请填写正确的期数'}}">累计逾期期数</th>
            <th field="loaninforeport_overduehigh" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'length[1,2]',invalidMessage:'请填写正确的期数'}}">最高逾期期数</th>
            <!-- <th field="loaninforeport_classify" width="10%" align="center" editor="numberbox">五级分类状态</th> -->
            <th field="loaninforeport_classify" width="10%" align="center" data-options="editor:{type:'combobox',
                    formatter:function(value,row){
                        return value;
                    },
                    options:{
                        valueField:'loaninforeport_classify',
                        textField:'loaninforeport_classifyName',
                        data:[
                            {'loaninforeport_classify':'1','loaninforeport_classifyName':'正常'},
                            {'loaninforeport_classify':'2','loaninforeport_classifyName':'关注'},
                            {'loaninforeport_classify':'3','loaninforeport_classifyName':'次级'},
                            {'loaninforeport_classify':'4','loaninforeport_classifyName':'可疑'},
                            {'loaninforeport_classify':'5','loaninforeport_classifyName':'损失'},
                            {'loaninforeport_classify':'9','loaninforeport_classifyName':'未知'}
                        ],
                        required:true,
                        editable:false,
                        missingMessage:'此项不能为空'
                    }
            }">五级分类状态</th>
            <!-- <th field="loaninforeport_accounstate" width="10%" align="center" editor="numberbox">账户状态</th> -->
            <th field="loaninforeport_accounstate" width="10%" align="center" data-options="editor:{type:'combobox',
                    formatter:function(value,row){
                        return value;
                    },
                    options:{
                        valueField:'loaninforeport_accounstate',
                        textField:'loaninforeport_accounstateName',
                        data:[
                            {'loaninforeport_accounstate':'1','loaninforeport_accounstateName':'正常'},
                            {'loaninforeport_accounstate':'2','loaninforeport_accounstateName':'逾期'},
                            {'loaninforeport_accounstate':'3','loaninforeport_accounstateName':'结清'},
                            {'loaninforeport_accounstate':'4','loaninforeport_accounstateName':'呆账'},
                            {'loaninforeport_accounstate':'5','loaninforeport_accounstateName':'转出'}
                        ],
                        required:true,
                        editable:false,
                        missingMessage:'此项不能为空'
                    }
            }">账户状态</th>
            <th field="loaninforeport_repaystatus" width="10%" align="center" data-options="editor:{type:'textbox',options:{required:true,missingMessage:'此项不能为空',validType:'length[1,24]',invalidMessage:'请填写正确的内容'}}">24月(账户)还款状态</th>
            <!-- <th field="loaninforeport_infotips" width="10%" align="center" editor="numberbox">账户拥有者信息提示</th> -->
            <th field="loaninforeport_infotips" width="10%" align="center" data-options="editor:{type:'combobox',
                    formatter:function(value,row){
                        return value;
                    },
                    options:{
                        valueField:'loaninforeport_infotips',
                        textField:'loaninforeport_infotipsName',
                        data:[
                            {'loaninforeport_infotips':'1','loaninforeport_infotipsName':'已开立账户'},
                            {'loaninforeport_infotips':'2','loaninforeport_infotipsName':'新账户开立'}
                        ],
                        required:true,
                        editable:false,
                        missingMessage:'此项不能为空'
                    }
            }">账户拥有者信息提示</th>
            <th field="loaninforeport_contractwork" width="10%" align="center" data-options="editor:{type:'datebox',options:{formatter:myformatter2,parser:myparser2,required:true,editable:false,missingMessage:'此项不能为空'}}">合同生效日期</th>
            <th field="loaninforeport_contractdown" width="10%" align="center" data-options="editor:{type:'datebox',options:{formatter:myformatter2,parser:myparser2,required:true,editable:false,missingMessage:'此项不能为空'}}">合同终止日期</th>
            <th field="loaninforeport_contractmoney" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'digits'}}">贷款合同金额</th>
            <!-- <th field="loaninforeport_workststus" width="10%" align="center" editor="numberbox">合同有效状态</th> -->
            <th field="loaninforeport_workststus" width="10%" align="center" data-options="editor:{type:'combobox',
                    formatter:function(value,row){
                        return value;
                    },
                    options:{
                        valueField:'loaninforeport_workststus',
                        textField:'loaninforeport_workststusName',
                        data:[
                            {'loaninforeport_workststus':'0','loaninforeport_workststusName':'有效'},
                            {'loaninforeport_workststus':'1','loaninforeport_workststusName':'无效'}
                        ],
                        required:true,
                        editable:false,
                        missingMessage:'此项不能为空'
                    }
            }">合同有效状态</th>
            <th field="start_time" width="10%" align="center">生成时间</th>
            <th field="update_time" width="10%" align="center">更新时间</th>
        </tr>
        </thead>
    </table>
 
    <div id="tb" style="height:auto">
        <div style="margin-bottom:5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">新增</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeit()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()">保存</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">取消</a>
            <a href="javscript:;" onclick="exportReport();" class="easyui-linkbutton" iconCls="icon-print" plain="true">导出</a>
        </div>
        <form action="../../report/loaninforeport/loaninfo_report_underline" method="post" id="searchTable">
            <div>
                更新日期 :<input id="month_time" name="month_time" data-options="required:true" value="{$search_array.month_time}">
                合同编号: <input class="easyui-textbox" name="select_num" id="select_num" value="{$search_array.select_num}" data-options="prompt:'搜索合同编号...'" style="width:150px"></input>
                客户姓名: <input class="easyui-textbox" name="select_name" id="select_name" value="{$search_array.select_name}" data-options="prompt:'搜索姓名...'" style="width:150px"></input>
                <a href="javascript:;" onclick="submitSearch();" class="easyui-linkbutton" iconCls="icon-search">查询</a>
                <a href="javascript:;" onclick="resetSearch();" class="easyui-linkbutton" iconCls="icon-clear">重置</a>
            </div>
        </form>
    </div>
</div>
    
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/report/loaninfo_report_underline.js"></script>
    <script type="text/javascript">
        $(function(){
            var json='{$report_json}';
            var array=eval('('+json+')');
            // console.log(array);
            $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', array);
        });


        var editIndex = undefined;
        function endEditing(){
            if (editIndex == undefined){return true}
            if ($('#dg').datagrid('validateRow', editIndex)){
                // var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'loaninforeport_workststus'});
                // var loaninforeport_workststusName = $(ed.target).combobox('getValue');
                // $('#dg').datagrid('getRows')[editIndex]['loaninforeport_workststus'] = loaninforeport_workststusName;
                $('#dg').datagrid('endEdit', editIndex);
                // alert(loaninforeport_workststusName);
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }
        function onClickRow(index){
            if (editIndex != index){
                if (endEditing()){
                    $('#dg').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                    editIndex = index;
                } else {
                    $('#dg').datagrid('selectRow', editIndex);
                }
            }
        }
        function append(){
            if (endEditing()){
                $('#dg').datagrid('appendRow',{status:''});
                editIndex = $('#dg').datagrid('getRows').length-1;
                $('#dg').datagrid('selectRow', editIndex)
                        .datagrid('beginEdit', editIndex);
            }
        }
        function removeit(){
            if (editIndex == undefined){return}
            $('#dg').datagrid('cancelEdit', editIndex)
                    .datagrid('deleteRow', editIndex);
            editIndex = undefined;
            var rowstr = $("#dg").datagrid('getChanges');
            var url = "../../report/loaninforeport/loaninfo_report_underline";
            $.ajax({
                type: "POST",
                async: true,
                data: {"delData":rowstr},
                url: url,
                success: function(d){
                    $("#dg").datagrid('acceptChanges');
                },
                error: function(e){
                    alert(e);
                }
            });
        }
        function accept(){
            if (endEditing()){
                var rowstr = $("#dg").datagrid('getChanges');
                // var rowstr = JSON.stringify(rowstr);
                // alert(rowstr);
                var url = "../../report/loaninforeport/loaninfo_report_underline";
                $.ajax({
                    type: "POST",
                    async: true,
                    data: {"addData":rowstr},
                    url: url,
                    success: function(d){
                        // console.log(d);
                        $("#dg").datagrid('acceptChanges');
                    },
                    error: function(e){
                        alert(e);
                    }
                });
            }
        }
        function reject(){
            $('#dg').datagrid('rejectChanges');
            editIndex = undefined;
        }
        function getChanges(){
            var rows = $('#dg').datagrid('getChanges');
            alert(rows.length+' rows are changed!');
        }
    </script>
</body>
</html>